import { randomString } from '../utils/other.js'
import { uploadOss } from './myResume.js'

// export default {
	// function install(Vue, options) {
		function install(file, isAccept = false) {
			console.log(file);
			return new Promise((resolve, reject) => {
				let imgUrl = ''
				uploadOss().then(response => {
					const info = response.data.data
					const randomStr = randomString(13)
					const headers = {
						'Content-Type': 'multipart/form-data',
						'Access-Control-Allow-Origin': '*'
					}
					const param = {
						key: randomStr,
						policy: info.policy,
						OSSAccessKeyId: info.accessKeyId,
						success_action_status: 200,
						signature: info.signature,
						file: file.tempFile,
						// chunk: 0,
					}
					// uni.request({
					//     url: info.host, //仅为示例，并非真实接口地址。
					//     data: param,
					// 	// method:"POST",
					//     // header: headers,
					//     success: (res) => {
					//         console.log(res.data);
					// 		const url = info.host + '/' + randomStr
					// 		console.log(url,'sss')
					// 		resolve(url)
					//     }
					// });
					uni.showLoading({
					    title: '上传中...'
					});
					uni.uploadFile({
						url: info.host, 
						filePath: file.tempFilePath,
						// fileType:file.type===1?'image':'video',
						name: 'file',
						// header:headers,
						formData:param,
						success: (uploadFileRes) => {
							uni.hideLoading();
							const url = info.host + '/' + randomStr
							console.log(url,'sss')
							resolve(url)
						},
						fail:(err)=>{
							console.log(err);
						}
					});
					
				})
			})
		}
	// }
// }

module.exports = {install}
